package com.lagou.edu.service;

import com.lagou.edu.pojo.Comment;
import com.lagou.edu.repository.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Optional;


@Service
public class CommentService {

    @Autowired
    private CommentRepository commentRepository;

    @Cacheable(cacheNames = "comment")
    public Comment findCommentById(Integer id){
        Optional<Comment> optional = commentRepository.findById(id);
        if(optional.isPresent()){
            Comment comment = optional.get();
            return comment;
        }

        return null;
    }
}
